//
//  WZXSecondTableViewCell.m
//  WWLNetease
//
//  Created by dllo on 15/12/22.
//  Copyright © 2015年 Echo.Jobs. All rights reserved.
//

#import "WZXSecondTableViewCell.h"

@implementation WZXSecondTableViewCell

- (instancetype) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self createSubView];
    }
    return self;
    
}

- (void)createSubView {
    
#pragma mark - 图片
    self.headImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10 * SIZE, 10 * SIZE, 90 * SIZE, 75 * SIZE)];
    
    [self.contentView addSubview:self.headImageView];
#pragma mark - 小标题
    self.titleLabel = [[UILabel alloc] init];
    self.titleLabel.frame = CGRectMake(110 * SIZE, 10 * SIZE, 250 * SIZE, 30 * SIZE);
    
    [self.contentView addSubview:self.titleLabel];
    
#pragma mark - 小详情
    self.describeLabel = [[UILabel alloc] initWithFrame:CGRectMake(110 * SIZE, 50 * SIZE, 250 * SIZE, 40 * SIZE)];
    self.describeLabel.font = [UIFont systemFontOfSize:14.0 * SIZE];
    self.describeLabel.textColor = [UIColor lightGrayColor];
    self.describeLabel.numberOfLines = 0;
    
    [self.contentView addSubview:self.describeLabel];
    
#pragma mark - 跟帖
    // 将UITextField当做label来用,因为UITextField可以设置圆角,将它的用户交互关闭
    self.followUpLabel = [[UITextField alloc] initWithFrame:CGRectMake(300 * SIZE, 75 * SIZE, 70 * SIZE, 15 * SIZE)];
    self.followUpLabel.center = CGPointMake(330 * SIZE, 82.5 * SIZE);
    // 设置文字的对齐方式
    self.followUpLabel.textAlignment = NSTextAlignmentCenter;
    self.followUpLabel.font = [UIFont systemFontOfSize:11.0 * SIZE];
    self.followUpLabel.borderStyle = UITextBorderStyleRoundedRect;
    self.followUpLabel.userInteractionEnabled = NO;
    self.followUpLabel.textColor = [UIColor lightGrayColor];
    [self.contentView addSubview:self.followUpLabel];
    
#pragma mark - 左下角角标图片
    self.numImageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"vote_multi_tag@2x.png"]];
    self.numImageV.frame = CGRectMake(10 * SIZE, 70 * SIZE, 20 * SIZE, 15 * SIZE);
    [self.contentView addSubview:self.numImageV];
    
#pragma mark - 左下角角标label
    self.numLabel = [[UILabel alloc] initWithFrame:CGRectMake(10 * SIZE, 70 * SIZE, 20 * SIZE, 15 * SIZE)];
    [self.contentView addSubview:self.numLabel];
    
      
}

-(void)setModel:(WZXButtonModel *)model {

    _model = model;
    self.titleLabel.text = self.model.title;
    self.describeLabel.text = self.model.digest;
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:self.model.imgsrc] placeholderImage:nil];
    
#pragma mark - 请求跟帖数
    CGFloat replayC = [self.model.replyCount floatValue];
    if (replayC > 0) {
        NSString *replayStr = [NSString stringWithFormat:@"%.0f跟帖", replayC];
        if (replayC >= 10000 ) {
            replayStr = [NSString stringWithFormat:@"%.1f万跟帖", replayC / 10000];
        }
        NSInteger lenth = replayStr.length;
        CGFloat w = (lenth + 2 * SIZE) * 8.0 * SIZE + 5 * SIZE;
        CGRect temp = self.followUpLabel.frame;
        temp.size.width = w;
        self.followUpLabel.frame = temp;
        self.followUpLabel.center = CGPointMake(330 * SIZE, 82.5 * SIZE);
        self.followUpLabel.text = replayStr;
    }else
    {
        self.followUpLabel.borderStyle = UITextBorderStyleNone;
    }
    
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
